package com.sc.nft.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.NftRegionBinding;
import com.sc.nft.entity.dto.NftRegionBindingPageDTO;
import com.sc.nft.entity.vo.NftRegionBindingPageVO;
import com.sc.nft.entity.vo.NftRegionBindingUserVO;
import com.sc.nft.enums.RegionLevelEnum;
import com.sc.nft.mapper.NftRegionBindingMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * nft版权部分绑定(NftRegionBinding)表Dao层
 *
 * @author 王伟成
 * @since 2023-10-11 16:47:36
 */
@Slf4j
@Repository
public class NftRegionBindingDao extends ServiceImpl<NftRegionBindingMapper, NftRegionBinding> {

    public List<NftRegionBindingUserVO> listBindUserId() {
        return baseMapper.listBindUserId();
    }

    public Page<NftRegionBindingPageVO> nftRegionBindingPage(Page mp, NftRegionBindingPageDTO nftRegionBindingPageDTO) {
        return baseMapper.nftRegionBindingPage(mp, nftRegionBindingPageDTO);
    }

//    public List<NftRegionBinding> selectProvinceAndCityAndArea(String province, String city, String area) {
//        return baseMapper.listNftBindByProvinceAndCityAndRegion(province, city, area, DateUtil.date());
//    }

    public List<NftRegionBinding> selectProvinceAndCityAndAreaAndEffectiveTime(String province, String city, String area) {
        LambdaQueryWrapper<NftRegionBinding> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(NftRegionBinding::getProvinceName, province);
        wrapper.eq(NftRegionBinding::getCityName, city);
        wrapper.eq(NftRegionBinding::getRegionName, area);
        wrapper.ge(NftRegionBinding::getEffectiveTime, DateUtil.date());
        return list(wrapper);
    }


    public List<NftRegionBinding> selectProvinceIdAndCityIdAndAreaIdAndCollectionId(Long collectionId, Long provinceId, Long cityId, Long areaId, RegionLevelEnum regionLevel) {
        LambdaQueryWrapper<NftRegionBinding> wrapper = Wrappers.lambdaQuery();
        wrapper.in(Objects.nonNull(collectionId), NftRegionBinding::getCollectionId, collectionId);
        wrapper.eq(Objects.nonNull(provinceId), NftRegionBinding::getProvinceId, provinceId);
        wrapper.eq(Objects.nonNull(cityId), NftRegionBinding::getCityId, cityId);
        wrapper.eq(Objects.nonNull(areaId), NftRegionBinding::getRegionId, areaId);
        wrapper.eq(Objects.nonNull(regionLevel), NftRegionBinding::getRegionLevel, regionLevel);
        wrapper.orderByDesc(NftRegionBinding::getId);
        return list(wrapper);
    }

    public List<NftRegionBinding> selectByCollectionId(Long collectionId) {
        LambdaQueryWrapper<NftRegionBinding> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(NftRegionBinding::getCollectionId, collectionId);
        return list(wrapper);
    }


    public List<NftRegionBinding> selectByRegionId(String regionId) {
        LambdaQueryWrapper<NftRegionBinding> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(NftRegionBinding::getRegionId, regionId);
        return list(wrapper);
    }
}
